﻿using IniFile;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace WeighSystem.Interface
{
    public class Utils
    {
        /// <summary>
        /// 读配置文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Ident"></param>
        /// <param name="Default"></param>
        /// <returns></returns>]
        public static string  ReadConfig(string Section, string Property, string Default)
        {

            //var parser = new Ini(System.AppDomain.CurrentDomain.BaseDirectory + "\\config.ini");
            String path = System.AppDomain.CurrentDomain.BaseDirectory + "\\config.ini";
            /*Ini.Config
                .AllowHashForComments()
                .SetSectionPaddingDefaults(insideLeft: 1, insideRight: 1)
                .SetPropertyPaddingDefaults(left: 4);
                */
            string iniStr = File.ReadAllText(path);
            Ini ini = Ini.Load(iniStr);
            // Get number of sections
            int sectionCount = ini.Count;
            // Add a new section
            var section = new Section("New section");
            ini.Add(section);

            // foreach over the properties of a section
            foreach (Property property in section)
            {
                // Your code goes here
            }

            // You can also use regular LINQ operations

            // Check if there are any properties in a section
            if (section.Any())
            {
                // Your code goes here
            }
            //var ini = Ini.Load("config.ini");
            return iniStr;
        }
        /// <summary>
        /// 写配置文件
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Ident"></param>
        /// <param name="Default"></param>
        public static void WriteConfig(string Section, string Ident, string Default)
        {
            //var parser = new IniParser.FileIniDataParser();

            // parser.WriteFile(System.AppDomain.CurrentDomain.BaseDirectory + "\\config.ini", new IniData());
        }

    }
}
